// 3.给你一个非严格递增排列的数组nums，请你原地O(1)删除重复出现的元素，使每个元素只出现一次，元素的相对顺序应该保持一致。
// int * removeDuplicates(int* nums, int numsSize, int *newNumsSize) ;

#include <stdio.h>
#include <string.h>

int * removeDuplicates(int* nums, int numsSize, int *newNumsSize)
{
    if (numsSize == 0)
    {
        *newNumsSize = 0;
        return nums;
    }

    int pos = 0;
    for (int idx = 1; idx < numsSize; idx++)
    {
        if (nums[idx] != nums[pos])
        {
            pos++;
            nums[pos] = nums[idx];
        }
    }

    *newNumsSize = pos + 1;
    return nums;
}

int main()
{
    int nums[] = {1, 1, 2, 2, 3, 4, 4, 5};
    int numsSize = sizeof(nums) / sizeof(nums[0]);
    int newNumsSize;

    printf("原数组：");
    for (int idx = 0; idx < numsSize; idx++)
    {
        printf("%d", nums[idx]);
    }
    printf("\n");

    int *newNums = removeDuplicates(nums, numsSize, &newNumsSize);

    printf("去重后的数组：");
    for (int idx = 0; idx < newNumsSize; idx++)
    {
        printf("%d", newNums[idx]);
    }
    printf("\n");

    return 0;

}